<?php

namespace addons\Patrol\common\models;

use common\models\merchant\Member;

use Yii;

/**
 * This is the model class for table "{{%addon_oa_calendar}}".
 *
 * @property int $id ID
 * @property int $member_id 用户
 * @property string $title 主题
 * @property string $begin_date 开始日期
 * @property string $end_date 结束日期
 * @property int $remind 提醒时间
 * @property int $type 日程类型
 * @property string $attend 与会人员
 * @property int $address 地点
 * @property int $content 描述
 * @property int $repetition 1重复0不重复
 * @property int $status 状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 */
class PatrolPlan extends \common\models\base\BaseModel
{
    public $attend;
    public $classes;
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%addon_patrol_plan}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['status', 'created_at', 'updated_at'], 'integer'],
            [['member_id','begin_time', 'end_time','check_date','classes','place_id','classes_id','attend'], 'safe'],

        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'attend' => '员工',
            'classes' => '班次',
            'member_id' => '姓名',
            'place_id' => '地点',
            'classes_id' => '班次',
            'check_date' => '排班日期',
            'begin_time' => '开始时间',
            'end_time' => '结束时间',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',

        ];
    }
    /**
     * 关联用户
     *
     * @return \yii\db\ActiveQuery
     */
    public function getMember()
    {
        return $this->hasOne(Member::class, ['id' => 'member_id']);
    }
    public function getPlace()
    {
        return $this->hasOne(PatrolPlace::class, ['id' => 'place_id']);
    }
    public function getPatrolClasses()
    {
        return $this->hasOne(PatrolClasses::class, ['id' => 'classes_id']);
    }
    public function beforeSave($insert)
    {
        $this->merchant_id = Yii::$app->user->identity->merchant_id;

        return parent::beforeSave($insert);

    }
}
